package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import util.jdbc;


public class IformationDao {
	
	Connection conn = null;
    PreparedStatement psmt = null;
    ResultSet rs = null;
    String str=null;

	//查看
	public String look() throws Exception {
		conn = jdbc.getCon();
	    String sql = "select * from address_book_contact ";  
	    psmt = conn.prepareStatement(sql);
	    rs = psmt.executeQuery();
	    
	    //将查询结果进行打印
	    while(rs.next() ) {
			
	        String string=rs.getString("id")+" "+rs.getString("name")+ " "
	        +rs.getString("address")+" "+rs.getString("tele")+" "; 
	        str+=string+"    ";
		 
	} 
	    //将结果进行返回到用户界面
		return str;
	    
		
	}
	//新增
	public void add(String name_get,String address_get,String tele_get,String id_get) throws Exception {
		conn = jdbc.getCon();
	    String sql = "INSERT INTO address_book_contact ( id,name, address, tele) VALUE (" + id_get
				+ ", " + name_get + "," + address_get + "," + tele_get + "); ";  
	    psmt = conn.prepareStatement(sql);
	}
	//修改
	public void modify(String name_get,String address_get,String tele_get,String id_get) throws Exception {
		conn = jdbc.getCon();
	    String sql = "UPDATE address_book_contact SET name="+name_get+",address="
	    +address_get+",tele="+tele_get+" WHERE id="+id_get+"; ";  
	    psmt = conn.prepareStatement(sql);
		
	}
	//删除
	public void dele(String id_get) throws Exception {
		conn = jdbc.getCon();
		String sql = "DELETE FROM address_book_contact WHERE id = " + id_get + "; ";
		psmt = conn.prepareStatement(sql);
		
	}

}
